﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ATest.Helpers
{
    public static class HtmlHelpers
    {
        public static string DeleteLink(this HtmlHelper html, string linkText, object routeValues)
        {
            return html.DeleteLink(linkText, "Delete", html.ViewContext.RouteData.GetRequiredString("controller"), routeValues);
        }

        public static string DeleteLink(this HtmlHelper html, string linkText, string controler, object routeValues)
        {
            return html.DeleteLink(linkText, "Delete", controler, routeValues);
        }

        public static string DeleteLink(this HtmlHelper html, string linkText, string action, string controler, object routeValues)
        {
            var urlHelper = new UrlHelper(html.ViewContext.RequestContext);

            string url = urlHelper.Action(action, controler, routeValues);

            string format = @"<form method=""post"" action=""{0}"" class=""delete-link"" onsubmit=""return confirm('Are you html sure?');""><input type=""submit"" value=""{1}"" />{2}</form><a class=""delete-link"" style=""display:none;"" href=""{0}"">{1}</a>";

            string form = string.Format(format, html.AttributeEncode(url)
              , html.AttributeEncode(linkText)
              , html.AntiForgeryToken());
            //return form + html.RouteLink(linkText, routeName, routeValues, new { @class = "delete-link", style = "display:none;" });
            return form;
        }
    }
}
